using System;
using System.Web;
using System.Web.Services;
using IndiGoGameProcessor.Board;

namespace IndiGoGameProcessor
{
	public class WebServices : WebService
	{
		private IndiGoGameProcessor.Board.Board _board;
		
		public WebServices()
		{
			_board = new IndiGoGameProcessor.Board.Board(19);
		}
		
		[WebMethod]
		/// <summary>
		/// Place a bead on intersection at x, y.
		/// </summary>
		/// <param name='x'>X</param>
		/// <param name='y'>Y</param>
		/// <param name='isWhite'>true if bead is white, false if black.</param>
		/// <returns>Whether the move was successful</returns>
		public bool Move(int x, int y, bool isWhite)
		{
			//Todo: More thorough validation
			//Todo: State should persist; session? Database?
			//Todo: Move logic to controllers
			//Todo: Move state to models
			if(_board[x][y] == IntersectionState.Empty)
			{
				_board[x][y] = isWhite
					? IntersectionState.White
					: IntersectionState.Black;
				return true;
			}
			return false;
		}
	}
}